<template>
  <Layout title="备忘详情" :has-back="true" :has-tabbar="false" ref="layout">
    <view
      style="
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        padding: 20rpx;
        display: flex;
        flex-direction: column;
      "
    >
      <view style="flex: 1; min-height: 0">
        <view style="width: 100%; height: 100%">
          <Scroll>
            <u-form label-width="180rpx" :labelStyle="{ fontSize: '40rpx' }">
              <u-form-item label="提醒日期">
                <text style="font-size: 40rpx">{{
                  note.sendDatetime.split(" ")[0]
                }}</text>
              </u-form-item>
              <u-form-item label="是否完成">
                <view style="width: auto">
                  <u-tag
                    :type="getTag(note.isComplete).type"
                    :text="getTag(note.isComplete).text"
                    size="large"
                  ></u-tag>
                </view>
              </u-form-item>
              <view class="top">
                <u-form-item label="提醒内容" label-position="top">
                  <u-textarea
                    v-model="note.content"
                    height="700rpx"
                    :maxlength="-1"
                    :disabled="true"
                  ></u-textarea>
                </u-form-item>
              </view>
            </u-form>
          </Scroll>
        </view>
      </view>
      <u-button @click="edit" type="primary">
        <text style="font-size: 40rpx">编辑</text>
      </u-button>
    </view>
  </Layout>
</template>
<script>
import Layout from "@/pages/component/layout/index.vue";
import Scroll from "@/pages/component/scroll/index.vue";
import {
  editNoteByUuid,
  removeNoteByUuid,
  getNoteByPaginationAndUuid,
} from "@/api/note";

export default {
  components: { Layout, Scroll },
  onLoad(event) {
    this.note = JSON.parse(event.query);
    this.getNoteByPaginationAndUuid();
  },
  onShow() {
    if (this.firstFlag) {
      this.getNoteByPaginationAndUuid();
    }
  },
  data() {
    return {
      firstFlag: false,
      note: {
        sendDatetime: "",
      },
    };
  },
  methods: {
    async getNoteByPaginationAndUuid() {
      let result = await getNoteByPaginationAndUuid({
        pageSize: 10,
        currentPage: 1,
        uuid: this.note.uuid,
      });
      this.note = result.data.list[0];
    },
    async edit() {
      let noteJson = JSON.stringify(this.note);
      await uni.navigateTo({
        url: `/pages/note/detail/edit/index?note=${noteJson}`,
      });
      this.firstFlag = true;
    },
    getTag(isComplete) {
      if (isComplete === "1") {
        return {
          type: "success",
          text: "已完成",
        };
      } else if (isComplete === "2") {
        return {
          type: "error",
          text: "未完成",
        };
      }
    },
  },
};
</script>
